﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormLoaiCongNo : Form
    {
        public FormLoaiCongNo()
        {
            InitializeComponent();
            FormLoaiCongNoLoad();
        }
        public void FormLoaiCongNoLoad()
        {
            DataTable dt = LoaiCongNoDAO.getAll();
            dgvLoaiCongNo.DataSource = dt;
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {        
            FormLoaiCongNo formLoaiCongNo = this;
            FormChiTietLoaiCongNo formChiTietLoaiCongNo = new FormChiTietLoaiCongNo(ref formLoaiCongNo);
            formChiTietLoaiCongNo.ShowDialog();
        }

        private void dgvLoaiCongNo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormLoaiCongNo formLoaiCongNo = this;

            LoaiCongNoModel loaiCongNoModel = new LoaiCongNoModel();
            loaiCongNoModel.ID = dgvLoaiCongNo.CurrentRow.Cells["ID"].Value.ToString();
            loaiCongNoModel.Ten = dgvLoaiCongNo.CurrentRow.Cells["Ten"].Value.ToString();
            loaiCongNoModel.Ghi_chu = dgvLoaiCongNo.CurrentRow.Cells["Ghi_chu"].Value.ToString();

            FormChiTietLoaiCongNo formChiTietLoaiCongNo = new FormChiTietLoaiCongNo(loaiCongNoModel, ref formLoaiCongNo);
            formChiTietLoaiCongNo.ShowDialog();
            
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void FormLoaiCongNo_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            if (e.KeyCode == Keys.F4)
            {
                this.Dispose();
            }
        }

        private void FormLoaiCongNo_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormLoaiCongNo_Load);
        }

    }
}
